package com.ruoyi.problemtag.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.problemtag.domain.ProblemTag;
import com.ruoyi.problemtag.service.IProblemTagService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 题目标签Controller
 * 
 * @author wcc
 * @date 2023-11-15
 */
@RestController
@RequestMapping("/problemtag/problemtag")
public class ProblemTagController extends BaseController
{
    @Autowired
    private IProblemTagService problemTagService;

    /**
     * 查询题目标签列表
     */
    @PreAuthorize("@ss.hasPermi('problemtag:problemtag:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProblemTag problemTag)
    {
        startPage();
        List<ProblemTag> list = problemTagService.selectProblemTagList(problemTag);
        return getDataTable(list);
    }

    /**
     * 查询题目标签列表
     */
    @GetMapping("/api/list")
    public TableDataInfo lists(ProblemTag problemTag)
    {
        startPage();
        List<ProblemTag> list = problemTagService.selectProblemTagList(problemTag);
        return getDataTable(list);
    }

    /**
     * 导出题目标签列表
     */
    @PreAuthorize("@ss.hasPermi('problemtag:problemtag:export')")
    @Log(title = "题目标签", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProblemTag problemTag)
    {
        List<ProblemTag> list = problemTagService.selectProblemTagList(problemTag);
        ExcelUtil<ProblemTag> util = new ExcelUtil<ProblemTag>(ProblemTag.class);
        util.exportExcel(response, list, "题目标签数据");
    }

    /**
     * 获取题目标签详细信息
     */
    @PreAuthorize("@ss.hasPermi('problemtag:problemtag:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(problemTagService.selectProblemTagById(id));
    }

    /**
     * 新增题目标签
     */
    @PreAuthorize("@ss.hasPermi('problemtag:problemtag:add')")
    @Log(title = "题目标签", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProblemTag problemTag)
    {
        return toAjax(problemTagService.insertProblemTag(problemTag));
    }

    /**
     * 修改题目标签
     */
    @PreAuthorize("@ss.hasPermi('problemtag:problemtag:edit')")
    @Log(title = "题目标签", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProblemTag problemTag)
    {
        return toAjax(problemTagService.updateProblemTag(problemTag));
    }

    /**
     * 删除题目标签
     */
    @PreAuthorize("@ss.hasPermi('problemtag:problemtag:remove')")
    @Log(title = "题目标签", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(problemTagService.deleteProblemTagByIds(ids));
    }
}
